<template>
  <div class="content">
    <div class="left">
      <div class="bread">
        <span class="lvyou">旅游攻略</span>
        <span>/</span>
        <span>攻略详情</span>
      </div>
      <h1>{{article.title}}</h1>
      <el-row class="footer" type="flex" align="middle" justify="end">
          <div>攻略：{{article.city.created_at}}</div>
          <span class="read">阅读：{{article.watch}}</span>
      </el-row>
      <div class="contentPost" v-html="article.content">
      </div>
      <el-row type="flex" justify="center" align="middle" class="daohang">
          <div class="comment">
              <i class="iconfont iconpinglun"></i>
              <p>评论(100)</p>
          </div>
          <div class="comment">
              <i class="iconfont iconstar1"></i>
              <p>收藏</p>
          </div>
          <div class="comment">
              <i class="iconfont iconfenxiang"></i>
              <p>分享</p>
          </div>
          <div class="comment">
              <i class="iconfont iconding"></i>
              <p>点赞(66)</p>
          </div>
      </el-row>
      <comments/>
    </div>
    <div class="right">
        <h4>相关攻略</h4>
        <nuxt-link :to="`/post/detail?id=${item.id}`" v-for="(item,index) in strategyList" :key="index">
            <el-row class="to_item" type="flex" justify="space-between">
            <img :src="item.images[0]" alt="">
            <div class="contents">
                <div class="title">{{item.title}}</div>
                <div class="time">2020-01-04 3:11 阅读 {{item.watch}}</div>
            </div>
        </el-row>
        </nuxt-link>
        
    </div>
  </div>
</template>

<script>
import comments from '@/components/post/comments';
export default {
    components: {
        comments
    },
    data(){
        return {
            article: {
                city:{}
            },
            // 相关攻略数组
            strategyList:[]
        }
    },
    mounted(){
        // 发送请求获取文章详情数据
        this.getPost();
        // 发送请求获取相关攻略文章列表
        this.$axios({
            url:"/posts/recommend",
            params:{
                id: this.$route.query.id
            }

        }).then(res=>{
            // console.log("获取成功");
            this.strategyList= res.data.data
            console.log(this.strategyList);
            
        })
    },
    
    watch:{
        // 监听当前路由是否发生变化
        $route(){
            this.getPost();
            // console.log("路由发生了变化");
            
        }
    },
    methods:{
        // 获取文章详情
        getPost(){
            this.$axios({
            url: "/posts",
            params:{
                id: this.$route.query.id
            }
        }).then(res=>{
            const {data} = res.data
            this.article = data[0]
            // console.log(res);
            
        })

        }
    }
};
</script>

.<style lang="less" scoped>
.content {
  width: 1000px;
  padding: 20px 0 0;
  margin: 0 auto;
  overflow: hidden;
  .left {
    width: 700px;
    float: left;
    .bread {
      font-size: 14px;
      color: #6d6f73;
      .lvyou {
        font-weight: 600;
        color: #303133;
      }
    }
    h1{
        padding: 20px 0;
        border-bottom: 1px solid #ddd;
       
    }
    .footer{
        font-size: 16px;
        color: #999;
        padding: 20px 0;
        .read{
            margin-left: 20px;
        }
    }
    .contentPost{
        width: 100%;
        /deep/ img{
            width: 100%;
            
        }
        /deep/ p:nth-child(7) img{
            width: 56px;
           
        }
    }
    .daohang{
        padding: 50px 0 30px;
        & div:nth-child(2) i{
            display: inline-block;
            transform: scale(1.4);
        }
        .comment{
            text-align: center;
            font-size: 14px;
            margin: 0 20px;
            i{
                font-size: 25px;
                color: #ffa500;
            }
            p{
                margin-top: 5px 0 0;
                color: #999
            }
        }

    }
  }
  .right{
      float: left;
      width: 280px;
      margin-left: 20px;
      h4{
          font-weight: normal;
        font-size: 18px;
        padding:0 0 10px;
        border-bottom: 1px solid #dddddd;
      }
      .to_item{
          padding: 20px 0;
           border-bottom: 1px solid #ddd;
          img{
              width: 100px;
              height: 80px;
          }
          .contents{
              display: flex;
              flex: 1;
              flex-direction: column;
              justify-content: space-between;
             padding-left: 5px;
              .title{
                  font-size: 16px;
                  color: #000; 
              }
              .time{
                      font-size: 12px;
                      color: #999
                  }
              
          }

      }
  }
}
</style>